﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility.Math
{
	public static class Vector2EX
	{
		public static bool IsAlmostZero (this Vector2 vec, float trashhold = 0.01f)
		{
			return vec.sqrMagnitude <= trashhold * trashhold;
		}

		public static float AngleTo (this Vector2 from, Vector2 to)
		{
			Vector2 fromRotated90 = new Vector2 (-from.y, from.x);
			float sign = (Vector2.Dot (fromRotated90, to) < 0) ? 1.0f : -1.0f;
			return Vector2.Angle (from, to) * sign;
		}

		public static float AngleTo (this Vector2Int from, Vector2Int to)
		{
			Vector2 fromRotated90 = new Vector2 (-from.y, from.x);
			float sign = (Vector2.Dot (fromRotated90, to) < 0) ? 1.0f : -1.0f;
			return Vector2.Angle (from, to) * sign;
		}

		public static Vector3 Vec3_x0y (this Vector2 vec2)
		{
			return new Vector3 (vec2.x, 0, vec2.y);
		}
	}
}